/*
 * @Description: 搜索页面
 * @Author: iamsmiling
 * @Date: 2021-06-09 14:51:55
 * @LastEditTime: 2021-06-15 17:48:13
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/button/roatet_button.dart';
import 'package:credit_business_circle/pages/search/search_controller.dart';
import 'package:credit_business_circle/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SearchPage extends StatelessWidget {
  const SearchPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SearchController>(builder: (_) {
      return Scaffold(
        appBar: AppBar(
          title: Text("搜索"),
          elevation: .5,
        ),
        backgroundColor: R.color.ffffffff,
        body: SingleChildScrollView(
          child: Container(
            // margin: EdgeInsets.symmetric(horizontal: R.dimen.dp10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  margin:
                      EdgeInsets.only(top: R.dimen.dp28, left: R.dimen.dp10),
                  child: Text(
                    "关键字仅搜索",
                    style: TextStyle(
                        fontSize: R.dimen.sp15,
                        color: R.color.ff111111,
                        fontWeight: FontWeight.w600),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(right: R.dimen.dp12),
                  child: DefaultTextStyle(
                    style: TextStyle(
                        fontSize: R.dimen.sp13, color: R.color.ff111111),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        for (SearchType type in SearchType.values)
                          Row(
                            children: [
                              Checkbox(
                                value: _.searchType == type,
                                materialTapTargetSize:
                                    MaterialTapTargetSize.shrinkWrap,
                                tristate: true,
                                side: BorderSide(
                                  color: R.color.ffcccccc,
                                ),
                                shape: RoundedRectangleBorder(
                                    borderRadius:
                                        BorderRadius.circular(R.dimen.sp3)),
                                onChanged: (bool? flag) {
                                  _.select(flag, type);
                                },
                                activeColor: R.color.ff00c28a,
                              ),
                              Text(type.name)
                            ],
                          )
                      ],
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(
                      top: R.dimen.dp20,
                      left: R.dimen.dp10,
                      right: R.dimen.dp10,
                      bottom: R.dimen.dp34),
                  padding:
                      EdgeInsets.only(left: R.dimen.dp13, right: R.dimen.dp2),
                  decoration: BoxDecoration(
                      border: Border.all(color: R.color.ffcccccc),
                      color: R.color.ffffffff,
                      borderRadius: BorderRadius.circular(R.dimen.sp5)),
                  child: TextField(
                    // onTap: () => Get.toNamed(AppRoutes.search),

                    decoration: InputDecoration(
                        isCollapsed: true,
                        contentPadding: EdgeInsets.only(
                            left: R.dimen.dp10,
                            top: R.dimen.dp8,
                            bottom: R.dimen.dp8),
                        prefixIcon: Container(
                          margin: EdgeInsets.only(right: R.dimen.dp10),
                          child: RotateButton(
                            onPressed: () => Future.value(),
                            label: Container(
                              child: Text(
                                "全部类型",
                                style: TextStyle(
                                    fontSize: R.dimen.sp11,
                                    color: R.color.ff222222),
                              ),
                              margin: EdgeInsets.only(right: R.dimen.dp10),
                            ),
                          ),
                        ),
                        prefixIconConstraints: BoxConstraints(
                          maxHeight: R.dimen.dp25,
                          minHeight: R.dimen.dp25,
                        ),
                        suffixIconConstraints: BoxConstraints(
                            maxHeight: R.dimen.dp25,
                            minHeight: R.dimen.dp25,
                            maxWidth: R.dimen.dp40,
                            minWidth: R.dimen.dp40),
                        suffixIcon: Container(
                          alignment: Alignment.center,
                          margin: EdgeInsets.only(right: R.dimen.dp4),
                          // padding: EdgeInsets.symmetric(
                          //     horizontal: R.dimen.dp10, vertical: R.dimen.dp4),
                          constraints: BoxConstraints(
                              maxHeight: R.dimen.dp25,
                              minHeight: R.dimen.dp25,
                              maxWidth: R.dimen.dp40,
                              minWidth: R.dimen.dp40),
                          decoration: BoxDecoration(
                              gradient: LinearGradient(
                                  colors: [R.color.ff1bbd8d, R.color.ff14ca94]),
                              borderRadius: BorderRadius.circular(R.dimen.sp5)),
                          child: Text(
                            "搜索",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                fontSize: R.dimen.sp11,
                                color: R.color.ffffffff),
                          ),
                        ),
                        hintText: "请输入关键词搜索，找渠道、资源搜您想要的！",
                        hintStyle:
                            TextStyle(fontSize: R.dimen.sp11, height: 1.2)),
                  ),
                ),
                Container(
                  child: Column(
                    children: [
                      Container(
                          margin: EdgeInsets.only(
                              left: R.dimen.dp10,
                              right: R.dimen.dp26,
                              bottom: R.dimen.dp26),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "最近搜索",
                                style: TextStyle(
                                    fontSize: R.dimen.sp15,
                                    color: R.color.ff111111,
                                    fontWeight: FontWeight.w600),
                              ),
                              GestureDetector(
                                child: Image.asset(R.image.trash),
                              )
                            ],
                          )),
                      for (String s in _.searchHistory)
                        GestureDetector(
                          onTap: () => Get.toNamed(AppRoutes.topicList),
                          child: Container(
                            margin: EdgeInsets.only(
                                left: R.dimen.dp26, right: R.dimen.dp26),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  s,
                                  style: TextStyle(
                                      height: 2,
                                      fontSize: R.dimen.sp15,
                                      color: R.color.ff555555),
                                ),
                                GestureDetector(
                                  onTap: () => _.delete(s),
                                  child: Image.asset(R.image.delete),
                                )
                              ],
                            ),
                          ),
                        )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    });
  }
}
